//
//  CampusQuestionHoverView.m
//  ShowYork
//
//  Created by hxh on 2021/3/29.
//  Copyright © 2021 hxh. All rights reserved.
//

#import "CampusQuestionDetailHoverView.h"

@interface CampusQuestionDetailHoverView ()
@property (nonatomic,strong)UIView *line;
@property (nonatomic,strong)UILabel *titleLb;
@property (nonatomic,strong)UILabel *countLb;
@property (nonatomic,strong)UILabel *replyLb;
@property (nonatomic,strong)UIImageView *replyIcon;
@property (nonatomic,strong)UIButton *replyButton;
@end

@implementation CampusQuestionDetailHoverView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setUI];
    }
    return self;
}
- (void)setUI{
    
    self.line = [[UIView alloc]init];
    self.line.backgroundColor = RGBA(86, 128, 250, 1);
    [self addSubview:self.line];
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(16);
        make.top.equalTo(self).offset(12);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(20);
    }];
    
    self.titleLb = [[UILabel alloc]init];
    self.titleLb.text = @"回答";
    self.titleLb.font = [UIFont boldSystemFontOfSize:20];
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.line);
        make.left.equalTo(self.line.mas_right).offset(10);
    }];
    self.countLb = [[UILabel alloc]init];
    self.countLb.text = @"(20)";
    self.countLb.textColor = C51;
    self.countLb.font = font(12);
    [self addSubview:self.countLb];
    [self.countLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.line);
        make.left.equalTo(self.titleLb.mas_right).offset(4);
    }];
    self.replyLb = [[UILabel alloc]init];
    self.replyLb.text = @"参与回答";
    self.replyLb.textColor = RGBA(113, 113, 113, 1);
    self.replyLb.font = font(12);
    [self addSubview:self.replyLb];
    [self.replyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.line);
        make.right.equalTo(self).offset(-16);
    }];
    self.replyIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"campus_reply_tag"]];
    [self addSubview:self.replyIcon];
    [self.replyIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.replyLb.mas_left).offset(-2);
        make.centerY.equalTo(self.replyLb);
    }];
    self.replyButton = [[UIButton alloc]init];
    [self.replyButton addTarget:self action:@selector(replyMethod) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.replyButton];
    [self.replyButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self);
        make.centerY.equalTo(self.line);
        make.size.mas_equalTo(CGSizeMake(100, 40));
    }];
}

- (void)replyMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(showReply)]) {
        [self.delegate showReply];
    }
}

- (void)setAnswerCount:(NSInteger)count{
    if (count >= 10000) {
        NSInteger max = count;
        if (max % 1000 == 0) {
            max += 1;
        }
        self.countLb.text = [NSString stringWithFormat:@"@(%@w)",[RPAppManager notRounding:count/10000.0f afterPoint:1]];
    }else{
        self.countLb.text = [NSString stringWithFormat:@"(%li)",(long)count];
    }
}

@end
